package tako.wisers.com.android.apis.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.IOUtils;

public class Configration extends Properties {
	private static final long serialVersionUID = 1L;
	private static final Configration conf = new Configration();
	private static final String CONF_FILE_NAME = "/conf.properties";

	private Configration() {
		InputStream is = null;
		try {
			is = this.getClass().getResourceAsStream(Global.CONF_PATH + CONF_FILE_NAME);
			load(is);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			if(is != null){
				IOUtils.closeQuietly(is);
			}
		}
	}
	
	public static Configration getInstance(){
		return conf;
	}
	
	public double getDouble(String key){
		String value = getProperty(key);
		Pattern pattern = Pattern.compile("[0-9]+[.]?[0-9]*");
		Matcher matcher = pattern.matcher(value);
		if(matcher.matches()){
			return new Double(value);
		}
		throw new IllegalArgumentException("This key is't mapping to a double");
	}
}
